#include "addbookface.h"
#include "ui_addbookface.h"

addBookface::addBookface(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::addBookface)
{
    ui->setupUi(this);

    appDir = QCoreApplication::applicationDirPath();
}

void addBookface::on_sureBtn_clicked()
{
    QFile file(appDir + "/bookInfo.txt");
    if (file.exists() == false)
    {
        qDebug() << "创建bookInfo文件" << endl;
    }

    file.open(QIODevice::WriteOnly | QIODevice::Append);

    QTextStream out(&file);
    // 设置编码为 UTF-8
    out.setCodec("UTF-8");

    out << ui->le_bookname->text();
    out << "+";
    out << ui->le_author->text();
    out << "+";
    out << ui->le_cnt->text();
    out << "\n";

    file.close();

    this->hide();
    ui->le_bookname->clear();
    ui->le_author->clear();
    ui->le_cnt->clear();

    emit updataView();
}

void addBookface::on_cancelBtn_clicked()
{
    this->hide();
    ui->le_bookname->clear();
    ui->le_author->clear();
    ui->le_cnt->clear();
}

addBookface::~addBookface()
{
    delete ui;
}
